<template>
  <div class="lable">
    <input
      type="checkbox"
      :checked="checked"
      :disabled="disabled"
      @change="changeCheck($event)">
    <label @click="clickLabel">
      {{ label }}<slot />
    </label>
  </div>
</template>

<script>
  export default {
    name: 'CmpCheckbox',

    model: {
      prop: 'checked',
      event: 'change'
    },

    props: {
      checked: Boolean,
      disabled: Boolean,
      label: String
    },

    methods: {
      changeCheck ($event) {
        this.$emit('change', $event.target.checked)
      },
      
      clickLabel(){
        this.$emit('change', !this.checked)
      }
    }
  }
</script>

<style lang='stylus' scoped>
.lable {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 32px;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -khtml-user-select: none;
  user-select: none;
  white-space: nowrap;

  &:hover {
    color: #24a7e3;

    & label {
      color: #24a7e3;
    }
  }

  & #inputCheck {
    cursor: pointer;
  }

  & label {
    cursor: pointer;
    height: 30px;
    line-height: 31px;
    color: #666666;
    white-space: nowrap;

    &:hover {
      color: #24a7e3;
    }
  }

  input[type="checkbox"] {
    width: 12px;
    height: 12px;
    display: inline-block;
    text-align: center;
    vertical-align: middle;
    line-height: 12px;
    position: relative;
    margin-right: 4px;
 }

 input[type="checkbox"]::before {
     content: "";
     position: absolute;
     top: 0;
     left: 0;
     background: #fff;
     width: 100%;
     height: 100%;
     border: 1px solid #CACDCF
 }

 input[type="checkbox"]:checked::before {
     font-family: "ipm-icon";
     content: "\e722";
     background-color: #24a7e3;
     color: #fff;
     position: absolute;
     top: 0;
     left: 0;
     width: 100%;
     border: 1px solid #24a7e3;
     font-size: 12px;
     font-weight: bold;
 }
}
</style>
